#include <iostream>

#include "tinyxml/tinyxml.h"
#include "include/ModelX3D.h"
#include "include/Pion.h"

using namespace std;

void ModelX3D::computeShapeIndex(const char * _definition, Model3D * _model3D)
{
   vector< vector<int> > * shapeIndexes = _model3D->getShapeIndexes();
   int i=0;
   int taille = strlen(_definition);
   vector<int> indexes_tmp;
   int coord_tmp;
   char buf[10];

   while( i < taille )
   {
      if( _definition[i] != ' ' && _definition[i] != ',' )
      {
         if( _definition[i] == '-' && _definition[i+1] == '1' )
         {
            shapeIndexes->push_back( (const vector<int>) vector<int>(indexes_tmp) );
            indexes_tmp.clear();
            i++;
         }
         else
         {            
            sscanf(string(_definition).substr(i).c_str(),
                   "%d",
                   &coord_tmp);
            sscanf(string(_definition).substr(i).c_str(),
                   "%s ",
                   buf);
            i+=strlen(buf);
            indexes_tmp.push_back(coord_tmp);
            continue;
         }
      }
      i++;
   }
}

void ModelX3D::computeShape(const char * _definition, Model3D * _model3D)
{
   int i=0;
   int i2=0;
   int taille = strlen(_definition);
   float point_tmp[3];

   while( i < taille )
   {
      if( _definition[i] != ' ' )
      {
         if( _definition[i] == ',' )
         {
            sscanf(string(_definition).substr(i2, i-i2-1).c_str(), 
                   "%f %f %f", 
                   &(point_tmp[0]),
                   &(point_tmp[1]),
                   &(point_tmp[2]));            
            _model3D->getShape()->addPoint(point_tmp[0], point_tmp[1], point_tmp[2]);
            i2=i+1;
         }
      }
      i++;
   }
}
